package cn.da.shuai.cool.system.model.entity.user;

import cn.da.shuai.cool.system.model.enums.user.UserStatusType;
import cn.da.shuai.cool.system.model.enums.user.UserType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.Range;

import java.io.Serial;
import java.io.Serializable;

@Setter
@Getter
@Schema(name = "用户查询", description = "用户查询视图对象")
public class SearchUserVo implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(title = "用户名")
    private String username;

    @Schema(description = "帐号状态（-1未知 1正常 2停用 3删除）")
    private UserStatusType status;

    @Schema(description = "用户编号")
    private String userNo;

    @Schema(description = "用户昵称")
    private String nickName;

    @Schema(description = "用户类型")
    private UserType userType;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "部门id")
    private Integer deptId;

    @Schema(description = "角色id")
    private Integer roleId;

    @Schema(description = "岗位id")
    private Integer postId;

    @NotNull
    @Range(min = 1, max = 100)
    @Schema(description = "当前页")
    private Integer pageNum = 1;

    @NotNull
    @Range(min = 1, max = 100)
    @Schema(description = "每页条数")
    private Integer pageSize = 10;

    @Schema(description = "排序字段")
    private String orderBy;

    public Integer getPageNum() {
        if (pageNum == null || pageNum < 1) {
            return 0;
        }
        return pageNum - 1;
    }
}
